<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,viewport-fit=cover">
    <title>WeUI</title>
    <link rel="stylesheet" href="../css/weui.css"/>

    <link rel="stylesheet" href="../css/jquery-weui.css">
    <link rel="stylesheet" href="../css/demos.css">

    <script src="../js/jquery-2.1.1.min.js"></script>
    <script src="../js/jquery-weui.js"></script>
    <script src="../layer/layer.js"></script>
    <script src="../js/main.js"></script>
    <title>搜索</title>
</head>

<body>

<div id="d" style="padding-bottom:10%;width:100%;height:0;margin-top: 1rem;background-color: black;margin-top: 0px;">
    <div style="width:70%;margin:auto auto;">
        <img src="../img/index/top.png" style="height: auto;width:100%; margin:auto auto;"/>
    </div>
</div>


<div class="weui-search-bar" id="searchBar">

    <form class="weui-search-bar__form">
        <div class="weui-search-bar__box">
            <i class="weui-icon-search"></i>
            <input type="search" class="weui-search-bar__input" id="searchInput" placeholder="搜索" required="">
            <a href="javascript:" class="weui-icon-clear" id="searchClear"></a>
        </div>
        <label class="weui-search-bar__label" id="searchText">
            <i class="weui-icon-search"></i>
            <span>搜索</span>
        </label>
    </form>
    <a href="javascript:" class="weui-search-bar__cancel-btn" onclick="findUser()" id="searchCancel1">确定</a>
    <a href="javascript:" class="weui-search-bar__cancel-btn" id="searchCancel2">取消</a>
</div>


<div class="weui-panel weui-panel_access">
    <div class="weui-panel__hd">搜索结果</div>

    <div class="weui-panel__bd" id="data">
        <!--<div  class="weui-media-box weui-media-box_appmsg">-->
            <!--<div class="weui-media-box__hd" style="border: 1px solid black;">-->
                <!--<img class=" weui-media-box__thumb" src="">-->
            <!--</div>-->
            <!--<div class="weui-media-box__bd">-->
                <!--<h4 class="weui-media-box__title"><a href="Expert/contact.html">专家a</a></h4>-->
                <!--<p class="weui-media-box__desc">专利资源&nbsp;&nbsp;&nbsp;<a href="Expert/contact.html">发布人详情</a></p>-->
            <!--</div>-->
        <!--</div>-->

    </div>
    <div class="weui-btn weui-btn_loading" style="color: darkslategray" id="load" onclick="loadData()">
        加载更多
    </div>
</div>
<script>
    $.ajaxSetup({
        xhrFields: {
            withCredentials: isCrossDomain
        }
    });
    var page = 1;
    var infos = "";
    var isNext = true;

    function loadData() {
        if (isNext) {
            $.post(mainurl + "need/findService", {page: page, info: infos}, function (data) {
                if (checkData(data)) {
                    isNext = data.data.hasNextPage;
                    if (!isNext) {
                        $("#load").text("");
                    }
                    page++;
                    var dat = data.data.list;
                    for (var i = 0; i < dat.length; i++) {
                        var d = dat[i];
                        var url = selectServiceUrl(d.rid) + "?ids=" + d.ids;
                        var clazz = d.resource;
                        var uid = d.uid;
                        var img = mainurl + d.img;
                        var info = d.name;
                        $("#data").append("<div  class=\"weui-media-box weui-media-box_appmsg\">\n" +
                            "            <div class=\"weui-media-box__hd\" style=\"border: 1px solid black;\">\n" +
                            "                <img class=\" weui-media-box__thumb\" src=\""+img+"\">\n" +
                            "            </div>\n" +
                            "            <div class=\"weui-media-box__bd\">\n" +
                            "                <h4 class=\"weui-media-box__title\"><a href=\""+url+"\">"+info+"</a></h4>\n" +
                            "                <p class=\"weui-media-box__desc\">"+clazz+"&nbsp;&nbsp;&nbsp;<a href=\"Expert/contact.html?id="+uid+"\">发布人详情</a></p>\n" +
                            "            </div>\n" +
                            "        </div>");

                    }
                }
            });
        }

    }

    function selectServiceUrl(n) {
        switch (n) {
            case 1:
                return "showService/release.html";
            case 2:
                return "showService/school.html";
            case 3:
                return "showService/soft.html";
            case 4:
                return "showService/team.html";
            case 5:
                return "showService/terrace.html";
        }
    }

    function findUser() {
        infos = $("#searchInput").val();
        isNext = true;
        page = 1;
        $("#data div").remove();
        loadData();
    }

    $(function () {
        loadData();
    })
</script>

</body>

</html>